<template>
    <div>
        <div class="ccui-multifunctional-table-wrapper">
            <el-table
                :data="showTableData"
                class="ccui-form-child-table"
                border
                show-summary
                :summary-method="getSummaries"
            >
                <el-table-column
                    show-overflow-tooltip
                    label="序号"
                    type="index"
                    align="center"
                    width="55"
                    fixed
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="acceptCode"
                    label="验收单编号"
                    width="150"
                    fixed
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="acceptName"
                    label="验收单名称"
                    width="200"
                    fixed
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="acceptTime"
                    label="验收日期"
                    width="100"
                />
                
                <el-table-column show-overflow-tooltip prop="acceptor" label="验收人"/>
                
                <el-table-column
                    show-overflow-tooltip
                    prop="materialName"
                    width="300"
                    label="设备物资名称"
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="materialState"
                    label="设备型号说明"
                    width="130"
                />
                
                <el-table-column show-overflow-tooltip prop="measureUnit" label="计量单位"/>
                
                <el-table-column
                    show-overflow-tooltip
                    prop="contractCode"
                    label="合同编号"
                    width="150"
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="settlementCount"
                    label="本次结算数量"
                    width="130"
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="acceptCount"
                    label="实际验收数量"
                    width="130"
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="manufacturerBrand"
                    label="生产厂家/品牌"
                    width="130"
                />
                
                <el-table-column
                    show-overflow-tooltip
                    prop="remarks"
                    label="备注"
                    width="100"
                />
            </el-table>
        </div>
    </div>
</template>

<script>
import BigNumber from "bignumber.js";
export default {
    name: "purchaseList",
    props: {
        settlementList: {
            type: Array
        }
    },
    data() {
        return {
            showTableData: [],
        };
    },
    // created() {
    //     this.$bus.$on("childTableData", val => {
    //         this.settlementList = val;
    //     })
    // },
    methods: {
        // 汇总 - 0802 - 16点34分 需求去除合计
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "合计";
                    return;
                }
                const values = data.map(item => Number(item[column.property]));
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            if (column.label == "订单数量" || column.label == "剩余可结算数量") {
                                let num = new BigNumber(+prev).plus(+curr).toFixed(3);
                                return num;
                            }
                            // else if (column.label == "结算单价") {
                            //   let num1 = Number(prev) + Number(curr);
                            //   return formatNumber(num1, 2);
                            // }
                        } else {
                            return (prev = " ");
                        }
                    }, 0);
                } else {
                    sums[index] = " ";
                }
            });
            return sums;
        }
    },
    filter: {},
    computed: {},
    watch: {
        settlementList: {
            handler(data) {
                if (data) {
                    this.showTableData = data.filter(e => e.isMainInventory == 0 && e.isOtherCost == 0 && !e.isCategories && e.acceptCode);
                }
            },
            immediate: true,
            deep: true
        }
    },
    // destroyed() {
    //     this.$bus.$off("childTableData");
    // }
};
</script>

<style lang="scss" scoped>
/deep/ .ccui-multifunctional-table-wrapper {
    .el-table td,
    .el-table th.is-leaf {
        border-right: 1px solid #edf2fc;
    }
}

.ml {
    margin-left: 10px;
}

.operation-group {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 20px;
}

/deep/ .hidden-row {
    display: none;
}

///deep/ .el-table__body-wrapper {
//  z-index: 1;
//}

/deep/ .el-table__fixed-header-wrapper {
    th {
        pointer-events: auto;
    }
}

/deep/ .el-table__fixed,
/deep/ .el-table__fixed-right {
    pointer-events: none;
    
    td {
        pointer-events: auto;
    }
}
</style>
